package management;

import java.awt.Toolkit;
import java.util.Arrays;

import javax.swing.GroupLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.LayoutStyle;

import dao.DaoFactory;
import dao.User;
import dao.UserDao;

import javax.swing.GroupLayout.Alignment;

public class Match extends JFrame {
	JLabel Id;
	JLabel name;
	JLabel prize;
	JLabel label1;
	JLabel label2;
	JLabel label3 ;
	JLabel label4 ;
	JLabel label5;
	JLabel label6;
	JLabel label7 ;
	JLabel label8;
	JLabel label9;
	JLabel label10;
	
	
	public Match() {
        init();
        setTitle("彩票购买抽奖程序");
        int width = Toolkit.getDefaultToolkit().getScreenSize().width;
		int height = Toolkit.getDefaultToolkit().getScreenSize().height;
		super.setLocation((width - 400) / 2, (height - 350) / 2);
	
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }
	
	     //User user1=new User();
	     //User [] use =new User[10];
	    
	 public void init() {
		 Id = new JLabel();
		 name = new JLabel();
		 prize = new JLabel();
		
		 label1 = new JLabel();
		 label2 = new JLabel();
		 label3 = new JLabel();
    	 label4 = new JLabel();
    	 label5 = new JLabel();
    	 label6 = new JLabel();
    	 label7 = new JLabel();
    	 label8 = new JLabel();
    	 label9 = new JLabel();
    	 label10 = new JLabel();
    	 User [] use =new User[10];
    	 UserDao userDao = DaoFactory.getUserDaoInstance();
    	 int j=0;
    	 int i=0;
    	 while(true)
    	 {
    		 i++;
    		 User user1=new User();
    		 if(j>8)
    			 break;
    		try {
				user1= userDao.QuerryById(i);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
    		if(user1.getPrize()>=1)
    		{
    			use[j]=user1;
    			j++;
    		}
    		
    	 }
     
    	
    	 
    	 label1.setText(use[0].getId()+"                                 " + use[0].getUsername());
    	 label2.setText(use[1].getId()+"                                 " + use[1].getUsername());
    	 label3.setText(use[2].getId()+"                                 " + use[2].getUsername());
    	 label4.setText(use[3].getId()+"                                 " + use[3].getUsername());
    	 label5.setText(use[4].getId()+"                                 " + use[4].getUsername());
    	 label6.setText(use[5].getId()+"                                 " + use[5].getUsername());
    
    	 
    	Id.setText("ID");
    	name.setText("用户");
    
    	
    
    	  // 为指定的 Container 创建 GroupLayout  
        GroupLayout layout = new GroupLayout(this.getContentPane());  
        this.getContentPane().setLayout(layout);  
        //创建GroupLayout的水平连续组，，越先加入的ParallelGroup，优先级级别越高。  
        
        GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup();  
       hGroup.addGap(60);//添加间隔  
        hGroup.addGroup(layout.createParallelGroup().addComponent(Id)  
                .addComponent(label1).addComponent(label2).addComponent(label3)
                .addComponent(label4)
                .addComponent(label5)
                .addComponent(label6)
                .addComponent(label7)
                .addComponent(label8)
                .addComponent(label9)
                .addComponent(label10));  
        hGroup.addGap(60);  
        hGroup.addGroup(layout.createParallelGroup().addComponent(name)  );  
        hGroup.addGap(40);  
        hGroup.addGroup(layout.createParallelGroup().addComponent(prize)  ); 
        hGroup.addGap(60);  
        layout.setHorizontalGroup(hGroup);  
        //创建GroupLayout的垂直连续组，，越先加入的ParallelGroup，优先级级别越高。  
        GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();  
        vGroup.addGap(20);  
        vGroup.addGroup(layout.createParallelGroup().addComponent(Id)
        		.addComponent(name)
        		.addComponent(prize));  
        
        vGroup.addGap(30);  
        vGroup.addGroup(layout.createParallelGroup().addComponent(label1)  );  
        vGroup.addGap(30);  
        vGroup.addGroup(layout.createParallelGroup().addComponent(label2)  );  
        vGroup.addGap(30);  
        vGroup.addGroup(layout.createParallelGroup().addComponent(label3)  );  
        vGroup.addGap(30);  
        vGroup.addGroup(layout.createParallelGroup().addComponent(label4)  );  
        vGroup.addGap(30);  
        vGroup.addGroup(layout.createParallelGroup().addComponent(label5)  );  
        vGroup.addGap(30);  
        vGroup.addGroup(layout.createParallelGroup().addComponent(label6)  );  
        vGroup.addGap(30);  
        vGroup.addGroup(layout.createParallelGroup().addComponent(label7)  );  
        vGroup.addGap(30);  
        vGroup.addGroup(layout.createParallelGroup().addComponent(label8)  ); 
        vGroup.addGroup(layout.createParallelGroup().addComponent(label9)  );  
        vGroup.addGap(30);  
        vGroup.addGroup(layout.createParallelGroup().addComponent(label10)  );  
        vGroup.addGap(30);  
       
        
      
        //设置垂直组  
        layout.setVerticalGroup(vGroup);  
        pack();
        this.setVisible(true);
	
	 }
}
